package com.feiyang.reactive;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

public class ReactiveProgram {

    public static void main(String[] args) throws InterruptedException {
        /*// 创建一个包含1到5的数据流
        Flux<Integer> flux = Flux.range(1, 5);

        // 对数据流进行转换，将每个元素乘以2
        Flux<Integer> transformedFlux = flux.map(i -> i * 2);

        // 订阅数据流并打印结果
        transformedFlux.subscribe(System.out::println);

        Mono<String> mono1 = Mono.just("Hello");
        Mono<String> mono2 = Mono.just("Reactor");
        Mono<String> mono3 = Mono.just("feiyang");
        Mono<String> resultMono = Mono.when(mono1, mono2, mono3).then(Mono.just("Combined"));
        System.out.println(resultMono.block());

        Flux<Integer> flux1 = Flux.just(1, 2, 3);
        Flux<Integer> flux2 = Flux.just(4, 5, 6);
        Flux<Integer> concatenatedFlux = flux1.concatWith(flux2);
        concatenatedFlux.subscribe(System.out::println);

        Flux<String> flux3 = Flux.just("A", "B", "C");
        Flux<Integer> flux4 = Flux.just(1, 2, 3);
        Flux<String> zippedFlux = flux3.zipWith(flux4, (s, i) -> s + i);
        zippedFlux.subscribe(System.out::println);

        // 使用 interval： 创建一个定时发射元素的 Flux
        Flux<Long> intervalFlux = Flux.interval(Duration.ofSeconds(1));
        intervalFlux.subscribe(System.out::println);

        // 等待几秒钟，然后让程序保持运行状态
        Thread.sleep(5000);*/

        Flux<Integer> delayedFlux = Flux.just(1, 2, 3, 4, 5).delayElements(Duration.ofSeconds(1));
        delayedFlux.subscribe(System.out::println);

        // 等待几秒钟，然后让程序保持运行状态
        Thread.sleep(6000);
        // 是吗
        int u = 10;
        // 第三方的
    }

}
